﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using DAL;
using Models;

namespace 公司CRM客户关系系统
{
    /// <summary>
    /// left 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务，请取消对下行的注释。
    [System.Web.Script.Services.ScriptService]
    public class left : System.Web.Services.WebService
    {

        /// <summary>
        /// 查询出当前登陆用户拥有权限的所有菜单
        /// </summary>
        /// <returns></returns>
        [WebMethod(EnableSession = true)]
        public List<MenuV2> SelectMenus()
        {
            V_Users u = Session["user"] as V_Users;
            int? roleID = u.RoleID;
            //查询出所有的一级菜单
            List<MenuV2> roots = BaseDAL.Select<MenuV2>("select *, null SubMenus, cast(1 as bit) Checked from menu m where parentid=0 and id in (select menuid from rolepowers where roleid=" + roleID + ")");
            //查询出所有的二级菜单
            foreach (MenuV2 menu in roots)
            {
                menu.SubMenus = BaseDAL.Select<MenuV2>("select *, null SubMenus, cast(1 as bit) Checked from menu m where parentid=" + menu.ID + " and id in (select menuid from rolepowers where roleid=" + roleID + ")");
            }
            return roots;
        }


    }
}
